package com.xbang.attendance.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xbang.attendance.entity.product.ProductCategory;
import com.xbang.attendance.service.ProductCategoryService;
import com.xbang.core.dao.support.GenericDaoSupport;
import com.xbang.core.service.impl.BaseServiceImpl;

/**
 * @author huawei
 * @email alonelaval@gmail.com
 */
@Service("productCategoryService")
public class ProductCategoryServiceImpl extends BaseServiceImpl implements ProductCategoryService{

	@Autowired
	private GenericDaoSupport genericDaoSupport;
	/*
	 * (non-Javadoc)
	 * @see com.xbang.attendance.service.ProductCategoryService#checkProductCategory(java.lang.String)
	 */
	@Override
	public Boolean checkProductCategory(String categoryCode) throws Exception {
		StringBuilder sb  = new StringBuilder("FROM ProductCategory category WHERE category.categoryCode = ?");
		List list =genericDaoSupport.getHibernateTemplate().find(sb.toString(),categoryCode);
		return null != list && !list.isEmpty() ;
	}
	/*
	 * (non-Javadoc)
	 * @see com.xbang.attendance.service.ProductCategoryService#getCategoryByName(java.lang.String)
	 */
	@Override
	public ProductCategory getCategoryByCode(String categoryCode)
			throws Exception {
		StringBuilder sb = new StringBuilder("FROM ProductCategory category WHERE category.categoryCode = ?");
		List list =genericDaoSupport.getHibernateTemplate().find(sb.toString(),categoryCode);
		return  list == null || list.isEmpty() ? null :(ProductCategory)list.get(0);
	}
	
}

